#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define endl "\n"
#define INF 1e18
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
int T,n,m,L,V,oppo;
struct car{
    int d;
    int a;
    int v;
}a[100010];
    int ll=0,minn=INF;
    int maxn=-1;
vector<int> found[100010],need;
int place[100010];
bool vis[100010];
int p[100010],acc[100010];
bool visvis[100010];
//bool mn[100010][100010];
pair<pair<double,double >,pair<bool,bool> >solve(int x){
    int d=a[x].d;
    int anow=a[x].a;
    int vnow=a[x].v;
    if(a[x].a==0){
        if(vnow>V)return {{d,L},{1,1}};
        else return {{-1,-1},{0,0}};
    }
    if(a[x].a>0){
        if(vnow>V)return {{d,L},{1,1}};
        else if(vnow==V)return {{d,L},{0,1}};
        else {
            double tt,dd;
            tt=(double)(V-vnow)/(double)anow;
            dd=(double)vnow*tt+0.5*(double)anow*tt*tt;
            if(d+dd>=L)return { {-1,-1},{0,0}};
            else return {{d+dd,L},{0,1}};
        }
    }
    if(a[x].a<0){
        if(vnow<V)return {{-1,-1},{0,0}};
        else if(vnow==V)return {{-1,-1},{0,0}};
        else {
            double tt,dd;
            tt=double(vnow-V)/(double)(fabs(anow));
            dd=(double)vnow*tt+0.5*(double)anow*tt*tt;
            if(d+dd>L)return {{d,L},{1,1}};
            else if(d+dd==L)return{{d,L},{1,0}};
            else if(d+dd<L)return{{d,d+dd},{1,0}};
        }
    }
}
bool bhy(const vector<int >&a,const vector<int >&b){
    bool suc;
    for(auto l:a){
        suc=0;
        for(auto t:b){
            if(t==l)suc=1;
        }
        if(!suc)return false;
    }
    return true;
}
int find(int x){
    if(x!=acc[x])acc[x]=find(acc[x]);
    return acc[x];
}
int sollve(){
    bool yes=0;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=m;j++){
            yes=0;
            if(bhy(found[j],found[i]))yes=1;
            if(yes&&find(i)!=find(j))acc[j]=find(i);
        }
    }
    for(int i=1;i<=m;i++){
        if(i==find(i))ll++;
    }
    return ll;
}
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        need.clear();
        oppo=0;
        ll=0;
        minn=INF;
        maxn=-1;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=m;i++){
                acc[i]=i;
                visvis[i]=0;
                found[i].clear();
        }
        for(int i=1;i<=n;i++){
            vis[i]=0;
        }
        for(int i=1;i<=n;i++){
            int ipt1,ipt2,ipt3;
            cin>>ipt1>>ipt2>>ipt3;
            a[i].d=ipt1,a[i].v=ipt2,a[i].a=ipt3;
        }
        for(int i=1;i<=m;i++){
            cin>>place[i];
        }
        sort(place+1,place +m +1);
        for(int i=1;i<=n;i++){
            auto ans=solve(i);
            double left=ans.fi.fi;
            double right=ans.fi.se;
            for(int j=1;j<=m;j++){
                if(place[j]>right)break;
                if(place[j]<left)continue;
                if(place[j]==left&&ans.se.fi)vis[i]=1,found[j].pb(i);//,///cout<<1<<j<<"caught"<<i<<"\n";//mn[j][i]=true,cnt++;
                if(place[j]==right&&ans.se.se)vis[i]=1,found[j].pb(i);//,cout<<2<<j<<"caught"<<i<<"\n";;//mn[j][i]=true,cnt++;
                if(place[j]<right&&place[j]>left)vis[i]=1,found[j].pb(i);//,cout<<3<<j<<"caught"<<i<<"\n";;//mn[j][i]=true,cnt++;
            }
            if(vis[i])oppo++;
        }
        cout<<oppo<<" "<<n-sollve()<<"\n";
    }
    return 0;
}
